/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bitetorrent.helper;

/**
 *
 * @author user
 */
public class Helper {

    /**
     * Convert array of string to string
     * @param strings
     * @return return empty string if <i>strings</i> is null
     */
    public static String ArrayStringToString(String[] strings) {
        StringBuilder sb = new StringBuilder();
        if (strings != null) {
            int length = strings.length - 1;
            int i = 0;

            for (i = 0; i < length; ++i) {
                sb.append(strings[i]);
                sb.append(", ");
            }

            sb.append(strings[i]);
        }

        return sb.toString();
    }

    public static byte[] concat(byte[] arr1, byte[] arr2) {
        byte[] result = new byte[arr1.length + arr2.length];
        System.arraycopy(arr1, 0, result, 0, arr1.length);
        System.arraycopy(arr2, 0, result, arr1.length, arr2.length);

        return result;
    }

    public static void main(String[] args) {
        byte[] arr1 = Converter.stringToBytes("saya");
        byte[] arr2 = Converter.stringToBytes("rezan");
        byte[] arr3 = concat(arr1, arr2);
        arr1 = Converter.stringToBytes("achmad");
        arr3 = concat(arr3, arr1);
        System.out.println(Converter.bytesToString(arr3));
    }
}
